# -*- coding:utf-8 -*-


def get_registers(user):
    u""" 非各个角色的管理员才会调用 """
    from users.models import OrganizationElevatorRelation, OrganizationAdminRoRelation, ElevatorAdminRoRelation, \
        AuthUserElevatorRelation
    if user.permission_type == 20:
        codes = AuthUserElevatorRelation.objects.filter_active(auth_user=user).values_list("register_code",
                                                                                           flat=True).distinct()
        return codes
    admin_role = user.admin_role
    codes = list()
    if not admin_role:
        return codes
    if admin_role.management_type == 20:
        codes = ElevatorAdminRoRelation.objects.filter_active(admin_role=admin_role).values_list("register_code",
                                                                                                 flat=True).distinct()
        return codes
    oarr = OrganizationAdminRoRelation.objects.filter_active(admin_role=admin_role).first()
    if not oarr:
        return codes
    org = oarr.organization
    if not org:
        return codes
    codes = OrganizationElevatorRelation.objects.filter_active(organization=org).values_list("register_code",
                                                                                             flat=True).distinct()
    return codes
